function rand_say() {
    var strAppend = '<div class="chat-box ';
    if (Math.floor(Math.random()*2) == 0){
        strAppend += 'chat-box-right';
    }
    strAppend += '"><div style="display: inline-block; ">';
    var chat_list = $(".chat-body");
    $.get(
        "https://v1.hitokoto.cn/",
        function (c) {
            strAppend += c.hitokoto+"  -- "+c.from;
            strAppend+='</div></div>';
            chat_list.append(strAppend);
            console.log(strAppend);
//                console.log("1",chat_list.height(), chat_list.get(0).scrollHeight, chat_list.scrollTop());
            chat_list.scrollTop(chat_list.get(0).scrollHeight - chat_list.height());
        }
    );

}

function clear_ui() {
    $(".list-group").children().remove();
    $(".card-title > div").html("选择一个人进行聊天...");
    $(".chat-body").children().remove();
}

function User_Login(strUID, strPWD, funCB) {
    $.ajax({
        url: "http://192.168.103.3:9000/user/login",
        type: "post",
        timeout: 3000,
        data: {
            "userid": strUID,
            "password": strPWD,
        },
        success: function (c, textStatus, jqXHR) {
            if (c.msg.length > 0){
                sessionStorage.setItem("im-session",c.msg);
                funCB(c.msg);

            }else{
                sessionStorage.setItem("im-session","");
                layer.msg("登录失败!");
            }

        },
        error : function (jqXHR, exception){
            layer.msg("连接服务器失败!");
        },
    });
}

function User_getSession() {
    return sessionStorage["im-session"];
}

function UI_UserFrends(objInfo) {
    var uList = $(".list-group");
    var strAppend = "";
    for(var i=0;i<objInfo.length;i++){
        strAppend += '<a href="#" class="list-group-item head-main"><img src="assert/default-head.png" class="head-show">';
        strAppend += '<h5 class="list-group-item-heading">'+objInfo[i].name+'<small>'+objInfo[i].uid+'</small></h5>';
        strAppend += '<p class="list-group-item-text"><i class="icon-circle status-on"></i>'+objInfo[i].email;
        strAppend += '</p></a>';
    }
    uList.append(strAppend);
}
function User_Info(strSessionID) {
    $.ajax({
        url: "http://192.168.103.3:9000/user/info",
        type: "post",
        timeout: 3000,
        data: {
            "token": strSessionID,
            "userid": "100000,100001",
        },
        success: function (c, textStatus, jqXHR) {
            // console.log(c);
            if(c.code == 200){

            }

        },
        error : function (jqXHR, exception){
            layer.msg("连接服务器失败!");
        },
    });
}

function User_Ping(strSessionID) {
    $.ajax({
        url: "http://192.168.103.3:9000/user/ping",
        type: "post",
        timeout: 3000,
        data: {
            "token": strSessionID,
            "userid": "100000",
        },
        success: function (c, textStatus, jqXHR) {
            // console.log(strSessionID,c);
            if( parseInt(c.msg) < 0 ){
                sessionStorage.setItem("im-session","");
            }
        },
        error : function (jqXHR, exception){
            layer.msg("连接服务器失败!");
        },
    });
}
